package com.xxg.renrensearch.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 查询商品sku信息
 *
 * @author xuxiaogang
 * @date 2021-11-26
 */
@Mapper
@Component
public interface RenrenShopGoodsOptionDao {
    /**
     * 在指定范围内查询数据
     *
     * @param start 开始ID
     * @param end   结束ID
     * @return 结果
     */
    @Select("select id,shop_id as shopId,goods_id as goodsId,title,thumb,price,cost_price as costPrice," +
            "original_price as originalPrice,stock,sales from renren_shop_goods_option where goods_id between #{start} and #{end}")
    List<RenrenShopGoodsOption> selectByIdRange(@Param("start") int start, @Param("end") int end);

    /**
     * 精确查询商品规格
     *
     * @param goodId 商品ID
     * @return 结果
     */
    @Select("select id,shop_id as shopId,goods_id as goodsId,title,thumb,price,cost_price as costPrice," +
            "original_price as originalPrice,stock,sales from renren_shop_goods_option where goods_id = #{goodId}")
    List<RenrenShopGoodsOption> selectByGoodId(@Param("goodId") int goodId);

    /**
     * 在指定范围内查询数据
     *
     * @param ids ID列表
     * @return 结果
     */
    @Select({"<script>",
            "select id,shop_id as shopId,goods_id as goodsId,title,thumb,price,cost_price as costPrice,",
            "original_price as originalPrice,stock,sales from renren_shop_goods_option where goods_id in ",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"})
    List<RenrenShopGoodsOption> selectByIds(@Param("ids") List<Integer> ids);

    /**
     * 在指定范围内查询数据
     *
     * @return 结果
     */
    @Select("select id,shop_id as shopId,goods_id as goodsId,thumb " +
            "from renren_shop_goods_option where thumb<>''")
    List<RenrenShopGoodsOption> select();

    /**
     * 根据商品ID列表删除记录
     *
     * @param ids ID列表
     */
    @Delete({"<script>",
            "delete from renren_shop_goods_option where goods_id in ",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"})
    void deleteByIds(@Param("ids") List<Integer> ids);
}